package com.beamfield.controller.manage;

import com.beamfield.common.ApiResult;
import com.beamfield.common.PageResult;
import com.beamfield.controller.common.BaseController;
import com.beamfield.model.BeamField;
import com.beamfield.service.manage.sys.BeamFieldService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;

/**
 * @author Zephyr
 * @description:
 * @date 2019/8/2
 */
@Controller
@RequestMapping("/cms/sys/init")
public class InitController extends BaseController {

    @Autowired
    private BeamFieldService beamFieldService;


    @RequestMapping("/beam_list")
    public ModelAndView beamList(){
        return new ModelAndView();
    }

    @RequestMapping("/edit_beam")
    public ModelAndView editBeam(){
        return new ModelAndView();
    }


    @RequestMapping("/readBeamField")
    @ResponseBody
    public PageResult readBeamField(HttpServletRequest request){
        String offset = request.getParameter("offset");
        String limit = request.getParameter("limit");
        String name = request.getParameter("name");
        return beamFieldService.readBeamField(offset, limit, name);
    }


    @RequestMapping("/deleteBeam")
    @ResponseBody
    public ApiResult deleteBeam(HttpServletRequest request){
        String beamId = request.getParameter("beam_id");
        return beamFieldService.deleteBeam(Long.parseLong(beamId));
    }

    @RequestMapping("/doSaveBeam")
    @ResponseBody
    public ApiResult doSaveBeam(HttpServletRequest request, BeamField beamField){
        Long userId = super.getUserId(request);
        return beamFieldService.saveBeam(beamField, userId);
    }
}
